Skip to content

feat: background placement for anytime tasks - #1248

Draft
Scofield626 wants to merge 8 commits into
masterfrom
anytime-background-runner
Draft

feat: background placement for anytime tasks#1248
Scofield626 wants to merge 8 commits into
masterfrom
anytime-background-runner

Conversation

@Scofield626

Copy link
Copy Markdown
Collaborator

An anytime: node can now set background: true. It compiles to CuAsyncTask<CuAnytimeRunner<T, Policy>, O>: the node keeps a single Whole poll step in the plan, and the worker thread runs one whole job per dispatch — age check, base(), refine quanta under the policy ZST, finish.

  • CuAnytimeRunner (doc(hidden), like the rest of the anytime machinery) holds the refinement loop in library code; every policy check const-folds exactly as in the emitted foreground blocks, with the same one-clock-read-per-quantum shape and stop-cause attribution.
  • AnytimePolicy::MAX_REFINES is read only by the runner's loop; a foreground plan still encodes the count positionally and never reads it.
  • The shared anchor_from_tov helper replaces the emitted anchor match; the foreground base block now calls it too.
  • Codegen composes the wrapper type through one background_inner_type helper at every background type site; background anytime nodes keep their single plan step (no expansion, no hoisted job local).
  • A background node does not need max_refines: a time bound alone closes the loop, which config validation already guarantees.
  • Inherited from CuAsyncTask: job-final delivery at the first poll at or after the worker finished; the input clone preserves tov, so max_age_ms absorbs upstream delay and pool queueing; task errors surface at the next poll; freeze cannot happen mid-job.

Tests: runner unit tests for every stop cause (converge, quanta bound, budget, stale skip, abort at base, quality floor), a composition test through CuAsyncTask asserting the status stamp survives the buffered-output copy, compile-pass apps (default and sim mode) covering a time-only background node and a named pool with resources, and a runnable example with foreground and background nodes sharing one task type.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Hi! Thanks for opening this pull request.

Because this is your first time contributing to this repository, please read our contributor guide:
https://github.com/copper-project/copper-rs/blob/master/CONTRIBUTING.md

The hooks run when the wrapped task is idle and are skipped while a
background run holds it, so a backgrounded anytime task now sees them.
One precomputed vec (inner_task_types: the type inside the optional
async wrapper) replaces the per-site background_inner_type calls and
the index threading through the type-building closures.
@Scofield626
Scofield626 force-pushed the anytime-background-runner branch from 6b741d4 to 27741f1 Compare August 4, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant